<template>
	<view class="z-upload">
		<view class="upload-btn" @click="chooseImg">
			<view class="add-icon">+</view>
			<view class="">{{uploadTipText}}</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				
			}
		},
		props:{
			uploadTipText:{ //上传时的提示文字
				type:String,
				default:"上传票据"
			},
			countImg:{  // 最大图片数
				type:Number,
				default:9
			},
			sizeType:{ //是否压缩
				type:Array,
				default:function(){
					return ['compressed']  //'original'/原图,'compressed'/压缩
				}
			},
			sourceType:{ //选择的位置
				type:Array,
				default:function(){
					return ['album','camera'];
				}
			}
		},
		methods:{
			chooseImg(){
				uni.chooseImage({
					count:this.countImg,
					sizeType:this.sizeType,
					sourceType:this.sourceType,
					success:(res) => {
						if(res.tempFilePaths.length > 0){
							this.resolveImgs(res.tempFilePaths)
						}
					},
					fail:(err) => {
						this.failImgs(err);
					}
				})
			},
			resolveImgs(imgs){
				this.$emit('resolveImgs',imgs);
			},
			failImgs(err){
				this.$emit('failImgs',err);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.z-upload{
		width: 160rpx;
		height: 160rpx;
		background-color: #f4f5f6;
		text-align: center;
		box-sizing: border-box;
		padding: 20rpx 0;
	}
	.add-icon{
		margin-bottom: -30rpx;
		font-size: 32rpx;
	}
</style>
